package com.mk.carcassonne.drawables;

import java.util.ArrayList;
import java.util.Date;
import java.util.Random;

import com.mk.carcassonne.Position;
import com.mk.carcassonne.R;

public class BrickRepository 
{
	private ArrayList<Brick> _bricks;
	
	private BrickFactory _brickFactory;
	
	public BrickRepository(BrickFactory brickFactory)
	{
		_brickFactory = brickFactory;
		
		_bricks = new ArrayList<Brick>();

		_bricks.add(_brickFactory.create(R.drawable.c_brick1, R.drawable.c_brick1_large, false, true));
		_bricks.add(_brickFactory.create(R.drawable.c_brick1, R.drawable.c_brick1_large, false, true));
		
		_bricks.add(_brickFactory.create(R.drawable.c_brick2, R.drawable.c_brick2_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick2, R.drawable.c_brick2_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick2, R.drawable.c_brick2_large, false, false));
		
		_bricks.add(_brickFactory.create(R.drawable.c_brick3, R.drawable.c_brick3_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick3, R.drawable.c_brick3_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick3, R.drawable.c_brick3_large, false, false));
		
		_bricks.add(_brickFactory.create(R.drawable.c_brick4, R.drawable.c_brick4_large, true, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick4, R.drawable.c_brick4_large, true, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick4, R.drawable.c_brick4_large, true, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick4, R.drawable.c_brick4_large, true, false));

		_bricks.add(_brickFactory.create(R.drawable.c_brick5, R.drawable.c_brick5_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick5, R.drawable.c_brick5_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick5, R.drawable.c_brick5_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick5, R.drawable.c_brick5_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick5, R.drawable.c_brick5_large, false, false));

		_bricks.add(_brickFactory.create(R.drawable.c_brick6, R.drawable.c_brick6_large, false, false));
				
		_bricks.add(_brickFactory.create(R.drawable.c_brick7, R.drawable.c_brick7_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick7, R.drawable.c_brick7_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick7, R.drawable.c_brick7_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick7, R.drawable.c_brick7_large, false, false));
		
		_bricks.add(_brickFactory.create(R.drawable.c_brick8, R.drawable.c_brick8_large, true, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick8, R.drawable.c_brick8_large, true, false));
		
		_bricks.add(_brickFactory.create(R.drawable.c_brick9, R.drawable.c_brick9_large, false, true));
		
		_bricks.add(_brickFactory.create(R.drawable.c_brick10, R.drawable.c_brick10_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick10, R.drawable.c_brick10_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick10, R.drawable.c_brick10_large, false, false));
		
		_bricks.add(_brickFactory.create(R.drawable.c_brick11, R.drawable.c_brick11_large, false, true));
		
		_bricks.add(_brickFactory.create(R.drawable.c_brick12, R.drawable.c_brick12_large, false, false));
		
		_bricks.add(_brickFactory.create(R.drawable.c_brick13, R.drawable.c_brick13_large, false, true));
		_bricks.add(_brickFactory.create(R.drawable.c_brick13, R.drawable.c_brick13_large, false, true));
		
		_bricks.add(_brickFactory.create(R.drawable.c_brick14, R.drawable.c_brick14_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick14, R.drawable.c_brick14_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick14, R.drawable.c_brick14_large, false, false));
				
		_bricks.add(_brickFactory.create(R.drawable.c_brick15, R.drawable.c_brick15_large, false, true));
		_bricks.add(_brickFactory.create(R.drawable.c_brick15, R.drawable.c_brick15_large, false, true));
		
		_bricks.add(_brickFactory.create(R.drawable.c_brick16, R.drawable.c_brick16_large, false, true));
		_bricks.add(_brickFactory.create(R.drawable.c_brick16, R.drawable.c_brick16_large, false, true));
		
		_bricks.add(_brickFactory.create(R.drawable.c_brick17, R.drawable.c_brick17_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick17, R.drawable.c_brick17_large, false, false));
				
		_bricks.add(_brickFactory.create(R.drawable.c_brick18, R.drawable.c_brick18_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick18, R.drawable.c_brick18_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick18, R.drawable.c_brick18_large, false, false));
		
		_bricks.add(_brickFactory.create(R.drawable.c_brick19, R.drawable.c_brick19_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick19, R.drawable.c_brick19_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick19, R.drawable.c_brick19_large, false, false));
		
		_bricks.add(_brickFactory.create(R.drawable.c_brick20, R.drawable.c_brick20_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick20, R.drawable.c_brick20_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick20, R.drawable.c_brick20_large, false, false));
		
		_bricks.add(_brickFactory.create(R.drawable.c_brick21, R.drawable.c_brick21_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick21, R.drawable.c_brick21_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick21, R.drawable.c_brick21_large, false, false));
		
		_bricks.add(_brickFactory.create(R.drawable.c_brick22, R.drawable.c_brick22_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick22, R.drawable.c_brick22_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick22, R.drawable.c_brick22_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick22, R.drawable.c_brick22_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick22, R.drawable.c_brick22_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick22, R.drawable.c_brick22_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick22, R.drawable.c_brick22_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick22, R.drawable.c_brick22_large, false, false));
		
		_bricks.add(_brickFactory.create(R.drawable.c_brick23, R.drawable.c_brick23_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick23, R.drawable.c_brick23_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick23, R.drawable.c_brick23_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick23, R.drawable.c_brick23_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick23, R.drawable.c_brick23_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick23, R.drawable.c_brick23_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick23, R.drawable.c_brick23_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick23, R.drawable.c_brick23_large, false, false));
		_bricks.add(_brickFactory.create(R.drawable.c_brick23, R.drawable.c_brick23_large, false, false));
		
		_bricks.add(_brickFactory.create(R.drawable.c_brick24, R.drawable.c_brick24_large, false, false));
	}
	
	public Brick getNext()
	{
		if(_bricks.size() > 0)
		{
			Random r = new Random(new Date().getTime());
			int index = r.nextInt(_bricks.size());
			Brick b = _bricks.get(index);
			_bricks.remove(index);
			return b;
		}
		
		return null;
	}
	
	public Brick getStartBrick()
	{
		return _brickFactory.create(R.drawable.c_brick3, R.drawable.c_brick3_large, false, false, new Position(0, 0));
	}
}
